home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_084 / ed / ed.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  106 lines

  1. /*
  2.  * Copyright 1987 Brian Beattie Rights Reserved.
  3.  *
  4.  * Permission to copy and/or distribute granted under the
  5.  * following conditions:
  6.  *
  7.  * 1). No charge may be made other than resonable charges
  8.  *    for reproduction.
  9.  *
  10.  * 2). This notice must remain intact.
  11.  *
  12.  * 3). No further restrictions may be added.
  13.  *
  14.  */
  15. #include <stdio.h>
  16. #include "tools.h"
  17. #include "ed.h"
  18. #include <setjmp.h>
  19. jmp_buf    env;
  20.  
  21. LINE    line0;
  22. int    curln = 0;
  23. int    lastln = 0;
  24. char    *inptr;
  25. static char    inlin[MAXLINE];
  26. int    nflg, lflg, pflg, pflag;
  27. int    line1, line2, nlines;
  28. extern char    fname[];
  29. int    version = 1;
  30.  
  31. intr()
  32. {
  33.     printf("Interrupt:\n");
  34.     longjmp(env, 1);
  35. }
  36.  
  37. main(argc,argv)
  38. int    argc;
  39. char    **argv;
  40. {
  41.     int    stat, i, j, prmpt;
  42.  
  43.     setbuf();
  44.     prmpt = isatty(0);        /* if interactive */
  45.     if(argc > 1)
  46.     {
  47.         for(i = 1; i < argc; i++)
  48.         {
  49.             if(doread(0,argv[i]))
  50.                 curln = 1;
  51.             strcpy(fname, argv[i]);
  52.             break;
  53.         }
  54.     }
  55.     while(1)
  56.     {
  57.         setjmp(env);
  58.         signal(2, intr);
  59.  
  60.         if(nflg)
  61.             fprintf(stdout,"%d: ",curln);
  62.         else if(prmpt)
  63.             fprintf(stdout,": ");
  64.  
  65.         if (fgets(inlin, sizeof(inlin),stdin) == NULL)
  66.         {
  67.             break;
  68.         }
  69.         if(*inlin == '!')
  70.         {
  71.             for(inptr = inlin; *inptr != NL; inptr++)
  72.                 ;
  73.             *inptr = EOS;
  74.             system(inlin+1);
  75.             continue;
  76.         }
  77.         inptr = inlin;
  78.         if(getlst() >= 0)
  79.             if(ckglob())
  80.             {
  81.                 if((stat = doglob()) >= 0)
  82.                 {
  83.                     curln = stat;
  84.                     continue;
  85.                 }
  86.             } else {
  87.                 if((stat = docmd(0)) >= 0)
  88.                 {
  89.                     if(stat == 1)
  90.                         doprnt(curln, curln);
  91.                     continue;
  92.                 }
  93.             }
  94.         if(stat == EOF)
  95.         {
  96.             exit(0);
  97.         }
  98.         if(stat == FATAL)
  99.         {
  100.             fputs("FATAL ERROR\n",stderr);
  101.             exit(1);
  102.         }
  103.         fputs("\007",stderr);
  104.     }
  105. }
  106.